package com.xyc.student.controller;

import com.xyc.student.exception.UserNotExistException;
import com.xyc.student.mapper.AssociateMapper;
import com.xyc.student.mapper.StuMapper;
import com.xyc.student.mapper.TeacherMapper;
import com.xyc.student.mapper.UserMapper;
import com.xyc.student.pojo.Associate;
import com.xyc.student.pojo.Stu;
import com.xyc.student.pojo.Teacher;
import com.xyc.student.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {
    @Autowired
    StuMapper stuMapper;

    @Autowired
    UserMapper userMapper;

    @Autowired
    TeacherMapper teacherMapper;

    @Autowired
    AssociateMapper associateMapper;

    @RequestMapping("/stuList")
    public List<Stu> stu() {
        return stuMapper.find();
    }

    @RequestMapping("/userList")
    public List<User> find() {
        return userMapper.find();
    }

    @ResponseBody
    @RequestMapping("/hello")
    public String hello(@RequestParam("user") String user) {
        if (user.equals("come")) {
            //抛出一个自定义异常
            throw new UserNotExistException();
        }
        return "Hello";
    }

    @RequestMapping("/ass")
    public List<Associate> ass() {
        return associateMapper.find();
    }

    @RequestMapping("/tea")
    public List<Teacher> tea() {
        return teacherMapper.find();
    }

}
